// const logTime = (name) => {
// 	console.log(`Log...${name} ` + new Date().toLocaleDateString());
// }
// exports.callback = () => {
// 	setTimeout(() => {
// 		logTime('callback1')
// 		setTimeout(() => {
// 			logTime('callback2')
// 		}, 100);
// 	}, 100);
// }

// const promise = (name, delay = 100) => new Promise(resolve => {
// 	setTimeout(() => {
// 		logTime(name)
// 		resolve()
// 	}, delay);
// })

// exports.promise = () => {
// 	promise('Promise 1')
// 		.then(promise('Promise 2'))
// 		.then(promise('Promise 3'))
// }

// exports.asyncAwait = async () => {
// 	await promise('Async/Await 1')
// 	await promise('Async/Await 2')
// 	await promise('Async/Await 3')
// 	await promise('Async/Await 4')
// }


// exports.event = async () => {
// 	const asyncFun = name => event => {
// 		setTimeout(() => {
// 			logTime(name)
// 			event.emit('end')
// 		}, 100);
// 		return event
// 	}
// 	const ary = [
// 		asyncFun('event 1'),
// 		asyncFun('event 2'),
// 		asyncFun('event 3')
// 	]
// 	const { EventEmitter } = require('events')
// 	const event = new EventEmitter()
// 	let i = 0
// 	event.on('end', () => i < ary.length && ary[i++](event))
// 	event.emit('end')
// }

// 习题
// https://github.com/su37josephxia/node_practice



const logTime = (name) => {
	console.log(`Log...${name} ` + new Date().toLocaleTimeString());
}

// 
exports.callback = (name) => {
	setTimeout(() => {
		logTime('callback 1')
		setTimeout(() => {
			logTime('callback 2')
		}, 100);
	}, 100);

}

const promise = (name, delay = 100) => new Promise(resolve => {
	setTimeout(() => {
		logTime(name)
		resolve()
	}, delay);
})
exports.promise = () => {
	promise('promise 1')
		.then(promise('promise 2'))
		.then(promise('promise 3'))
}


exports.asyncAwait = async () => {
	await promise('async/await 1')
	await promise('async/await 2')
	await promise('async/await 3')
	await promise('async/await 4')

}
